package com.starleague.trait;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.common.collect.Lists;
import com.starleague.entity.IEntityVisitor;

public abstract class AbstractTraitGroup
        extends AbstractTrait
        implements ITraitGroup
{
    private final List<? extends AbstractTrait> traitList;

    protected AbstractTraitGroup(String name,
                                 String label,
                                 Collection<? extends AbstractTrait> traitCollection)
    {
        super(name, label);
        this.traitList = Lists.newArrayList(traitCollection);
    }

    protected AbstractTraitGroup(String name,
                                 String label,
                                 AbstractTrait... traits)
    {
        super(name, label);
        this.traitList = Lists.newArrayList(traits);
    }

    protected AbstractTraitGroup(String name,
                                 String label)
    {
        super(name, label);
        this.traitList = new ArrayList<>();
    }

    protected AbstractTraitGroup()
    {
        // For serialization
        this.traitList = new ArrayList<>();
    }

    @Override
    public List<? extends AbstractTrait> getTraits()
    {
        return this.traitList;
    }

    @Override
    public AbstractTrait getTraitById(String traitId)
    {
        return TraitHelper.findTraitByTraitId(this.traitList, traitId);
    }

    @Override
    public void accept(IEntityVisitor visitor)
    {
        super.accept(visitor);
        visitor.visit(TRAITS, this.traitList);
    }
}
